<?php

include_once("../config.inc");
include_once(ROOT.'/database/config.php');

function open_login($type, $token_1st, $token_2nd, $token_3rd, $nickname, $head_url)
{
	$connect_id = mysql_connect(DB_URL, DB_USERNAME, DB_PASSWORD);
	if ($connect_id)
  {
  	mysql_select_db(DB_DBNAME, $connect_id);
  	
  	$sql = mysql_query("SELECT * FROM open_user WHERE " 
  		. "token_1st='" . $token_1st 
  		. "' AND token_2nd='" . $token_2nd 
  		. "' AND token_3rd='" . $token_3rd 
  		. "' AND type=" . $type);
  	if (0 == mysql_num_rows($sql))
  	{
  		//$data = mysql_fetch_array($sql);
  		mysql_query("INSERT INTO open_user (token_1st, token_2nd, token_3rd, nickname, head_url, local_user_id, type) VALUES ('" 
  			. $token_1st . "', '" . $token_2nd . "', '" . $token_3rd . "', '" . $nickname . "', '" . $head_url . "', " 
  			. 1 . ", " . $type.")");
  	}
  	else
  	{
  	}
  	
  	mysql_close($connect_id);
  }
}

function get_open_login($type)
{
	$connect_id = mysql_connect(DB_URL, DB_USERNAME, DB_PASSWORD);
	if ($connect_id)
  {
  	mysql_select_db(DB_DBNAME, $connect_id);
  	
  	$result = mysql_query("SELECT * FROM open_user WHERE type=" . $type);
  	if (0 == mysql_num_rows($result))
  	{
  	}
  	else
  	{
  		while ($row = mysql_fetch_array($result))
  		{
  			echo $row['nickname'];
  		}
  	}
  	
  	mysql_close($connect_id);
  }
}
?>
